// CheckVersionDlg.h : interface of the CCheckVersionDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#define WM_ON_START	WM_USER + 123
#define WM_ON_STEP	WM_USER + 124

class CCheckVersionDlg : public CDialogImpl<CCheckVersionDlg>,
	public cm::client_server::version_checker::subscriber
{
public:
	CCheckVersionDlg()
	{
	}
public:
	enum { IDD = IDD_DIALOG_CHECK_VERSION};

	BEGIN_MSG_MAP(CCheckVersionDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		MESSAGE_HANDLER(WM_CLOSE, OnClose)

		MESSAGE_HANDLER(WM_ON_START, OnStart)
		MESSAGE_HANDLER(WM_ON_STEP, OnStep)

	END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
		return CWindow::IsDialogMessage(pMsg);
	}

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		SetWindowLong(GWL_EXSTYLE,GetWindowLong(GWL_EXSTYLE) | WS_EX_LAYERED);
		::SetLayeredWindowAttributes(m_hWnd,0,(255 * 80) / 100,LWA_ALPHA);

		CString CaptionTxt;
		CaptionTxt.LoadString(IDS_CAPTION);
		SetWindowText(CaptionTxt);

		CenterWindow();

		return TRUE;
	}

	LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		DestroyWindow();
		::PostQuitMessage(0);
		return 0;
	}

	LRESULT OnStart(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
	{
		CProgressBarCtrl ProgressBar(GetDlgItem(IDC_PROGRESS_VERSION_CHECK));
		ProgressBar.SetRange32(0,lParam);
		return 0;
	}

	LRESULT OnStep(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
	{
		CProgressBarCtrl ProgressBar(GetDlgItem(IDC_PROGRESS_VERSION_CHECK));
		ProgressBar.SetPos(lParam);
		return 0;
	}

private:
	virtual void on_start(unsigned int steps)
	{
		PostMessage(WM_ON_START,0,steps);
	}
	virtual void on_step(unsigned int step)
	{
		PostMessage(WM_ON_STEP,0,step);
	}
	virtual void on_stop()
	{
	}
};
